<template>
    <div class="listDiv">
        <div class="searchDiv">
            <DateRange v-model:start="obj.req.starttime" v-model:end="obj.req.endtime" sph="匹配" eph="报修时间" />
            <el-select v-model="obj.req.state" placeholder="维修结果" class="search_select" clearable>
                <el-option v-for="(item,index) in globalData.faultStateList" :key="index" :label="item.text" :value="item.value" />
            </el-select>
            <el-input clearable placeholder="匹配设备名称/维修人员" v-model="obj.req.key" class="search_key" />
            <span class="btn search" @click="init">搜索</span>
            <span class="btn refresh" @click="obj.req.currentpage=1;init()"></span>
            <div class="searchRight">
                <!-- <span class="btn add" @click="add">添加</span>
                <span class="download" @click="export_"></span> -->
            </div>
        </div>
        <div class="table_box"><div class="table_" id="tb">
            <ul class="head">
                <li class="">设备编号</li>
                <li class="mw200">设备名称</li>
                <li class="">报修人员</li>
                <li class="mw200 wcen">报修时间</li>
                <li class="">故障图片</li>
                <li class="mw300">描述</li>
                <li class="">维修人员</li>
                <li class="wcen">维修状态</li>
                <li class="mw150 wcen">操作</li>
            </ul>
            <div class="body">
                <ul class="" v-for="x in obj.ary" :key="x">
                    <li class="">{{x.code}}</li>
                    <li class="mw200">
                        <el-tooltip class="box-item" effect="dark" :content="x.name" placement="top-start" :disabled="x.name.length<10">
                            <div class="lineOne pointer">{{x.name}}</div>
                        </el-tooltip>
                    </li>
                    <li class="">{{x.addusername}}</li>
                    <li class="mw200 wcen">{{x.intime}}</li>
                    <li class="">
                        <el-image v-for="(v,i) in x.imgs.split(',')" :key="i"  style="width: 40px; height: 40px" class="ml5" fit="cover" :preview-src-list="[proxy.$setting.globalUrl.fileurl+ '/fault/'+ v]" :src="proxy.$setting.globalUrl.fileurl+ '/fault/'+ v">
                            <template #error>
                                <div class="image-slot">
                                    <el-image style="width: 40px; height: 40px" fit="cover" src="https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg"/>
                                </div>
                            </template>
                        </el-image>
                    </li>
                    <li class="mw300">
                        <el-tooltip class="box-item" effect="dark" :content="x.msg" placement="top-start" :disabled="x.msg.length<17">
                            <div class="lineOne pointer">{{x.msg}}</div>
                        </el-tooltip>
                    </li>
                    <li class="">{{x.faultusername}}</li>
                    <li class="wcen">
                        <div :class="[proxy.$utils.find(globalData.faultStateList, x.state,'label')]">{{proxy.$utils.find(globalData.faultStateList, x.state)}}</div>
                    </li>
                    <li class="mw150 wcen">
                        <el-button class="edit_btn mr10" :type="x.faultuserid==''?'success':'primary'" @click="edit(x)">{{x.faultuserid==''?"指派":"查看"}}</el-button>
                        <DelConfirm class="" @yesClick="del(x)" />
                    </li>
                </ul>
            </div>
        </div>
        </div><Pager :value="obj.req" :init="init" />

        <el-dialog v-model="obj.drawer.design" :title="obj.drawer.designTitle" width="1000px" :close-on-click-modal="false" :destroy-on-close="true">
            <router-view @close="obj.drawer.design = false" @init="init" />
        </el-dialog>
    </div>
</template>

<script setup>
    import { reactive, getCurrentInstance, ref, toRefs, provide, computed } from 'vue'
    import DateRange from '@/components/date_range.vue'
    import Pager from '@/components/pager.vue'
    import DelConfirm from '@/components/del_confirm.vue'
    let { proxy } = getCurrentInstance()

    let obj = reactive({
        drawer: {
            design: false,
            designTitle: "",
        },
        ary: [],
        req: {
            currentpage: 1,
            pagesize: 10,
            count: 0,
            key: "",
            state:"",
            // endtime: "",
            // starttime: "",
            endtime: proxy.$utils.dateFormat(new Date(), "yyyy-MM-dd"),
            starttime: proxy.$utils.dateAddDay(new Date(), -7, "yyyy-MM-dd"),
        }
    });
    let init = () => {
        proxy.$ajax({
            url: '/fault/list',
            data: obj.req,
            bfLoading: true
        }).then(d => {
            // console.log(d)
            if(d.success){
                obj.ary = d.msg.list
                obj.req.count = d.msg.count
            }
        }).catch(() => { })
    }

    let editId = ref(0)
    provide("id", editId); //不能加.value
    let edit = x => {
        obj.drawer.design = true
        obj.drawer.designTitle = `${x.code} 指定维修人员`
        editId.value = x.fault_id;
    }

    let del = x => {
        proxy.$ajax({
            url: '/fault/delete',
            data: { fault_id: x.fault_id },
            bfLoading: true
        }).then(d => {
            // console.log(d)
            if(d.success){
                proxy.elMessageMixin("删除成功", "success")
                init()
            }else{
                proxy.elMessageMixin(d.err, 'error')
            }
        }).catch(() => { })
    }
</script>

<style scoped>
    ::-webkit-scrollbar { width:10px; background-color: #FFFFFF; }
    .search_select { margin-left: 10px; width:100px!important; }
    .search_key { width:200px!important; }
    #tb ul li.liflex { min-width: 50px; overflow: hidden; }
    #tb ul li.li1 { width: 75px; }
    #tb ul li.li2 { width: 130px; }
    #tb ul li.li3 { width: 105px; }
    #tb ul li.li5 { width: 105px; }
    #tb ul li.li6 { width: 75px; }
    #tb ul li.li7 { width: 155px; }
</style>